import 'package:ycbl/common/my_course_type.dart';
import 'package:ycbl/model/bl_error_entity.dart';
import 'package:ycbl/model/learn_course_detail_entity.dart';
import 'package:ycbl/net/repository/bl_repository.dart';
import 'package:ycbl/widget/provider/base_view_state_model.dart';

class LearnCourseDetailViewModel extends BaseViewStateModel {


  ///课程类型 是不可变的
  final MyCourseType courseType;
  final int mainId;
  LearnCourseDetailViewModel(this.mainId, this.courseType,);

  LearnCourseDetailEntity _learnCourseDetailEntity;

  ///课程详情
  LearnCourseDetailEntity get courseDetailEntity => _learnCourseDetailEntity;

  ///获取课程详情
  getLearnCourseDetail() {
    setBusy();
    if (courseType == MyCourseType.CLAZZ) { // 班课
      BLRepository.getLearnClassDetail(mainId, _onGetDetail, _onError);
    }else { // 一对一
      BLRepository.getLearnOneDetail(mainId, _onGetDetail, _onError);
    }
  }

  _onError(BLErrorEntity error) {
    setError(error);
  }

  _onGetDetail(LearnCourseDetailEntity courseDetailEntity) {
    _learnCourseDetailEntity = courseDetailEntity;
    setIdle();
  }

}